﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace IsmsExplorer.Infrastructure.RepositoryFramework.Configuration {
    public sealed class RepositoryMappingCollection : ConfigurationElementCollection {
        protected override ConfigurationElement CreateNewElement() {
            return new RepositoryMappingElement();
        }

        protected override object GetElementKey(ConfigurationElement element) {
            return ((RepositoryMappingElement)element).InterfaceShortTypeName;
        }

        public override ConfigurationElementCollectionType CollectionType {
            get {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override string ElementName {
            get {
                return RepositoryMappingConstants.ConfigurationElementName;
            }
        }

        public RepositoryMappingElement this[int index] {
            get {
                return (RepositoryMappingElement)this.BaseGet(index);
            }
            set {
                if (this.BaseGet(index) != null) {
                    this.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        public new RepositoryMappingElement this[string interfaceShortTypeName] {
            get {
                return (RepositoryMappingElement)this.BaseGet(interfaceShortTypeName);
            }
        }

        public bool ContainsKey(string keyName) {
            bool result = false;
            object[] keys = this.BaseGetAllKeys();
            foreach (object key in keys) {
                if ((string)key == keyName) {
                    result = true;
                    break;
                }
            }
            return result;
        }

    } // end public sealed class RepositoryMappingCollection : ConfigurationElementCollection
}

